<template>
  <div>
    <home-head title="添加联系人" />
    <div class="wrap">
      <van-address-edit :area-list="areaList"
                        show-postal
                        show-set-default
                        :area-columns-placeholder="['请选择', '请选择', '请选择']"
                        @save="onSave" />
    </div>
  </div>
</template>

<script>
import HomeHead from 'components/HomeHead'
import { areaList } from '@vant/area-data'
import { addContent } from 'api'
import { getToken } from 'utils'
import { Toast } from 'vant'
export default {
  name: 'contentAdd',
  data () {
    return {
      areaList
    }
  },
  methods: {
    onSave (params) {
      console.log(params)
      const { addressDetail, postalCode, name, tel, areaCode, isDefault } = params
      params = {
        address: addressDetail,
        cityId: postalCode,
        linkMan: name,
        mobile: tel,
        provinceId: areaCode,
        isDefault,
        token: getToken()
      }
      addContent(params).then(res => {
        if (res.data.code === 0) {
          Toast.success({
            message: '添加成功',
            duration: 500,
            onClose: () => {
              this.$router.push('/contlists')
            }
          })
        }
      })
    }
  },
  components: {
    HomeHead
  }
}
</script>

<style lang="scss" scoped>
.wrap {
  padding: 46px 0 50px;
}
</style>
